package main

import (
	"fmt"
	"log"
	"net"
	"net/rpc"
	"net/rpc/jsonrpc"

	"gitee.com/network-learning/rpc/3protobuf/pb"
)

func main() {
	conn, err := net.Dial("tcp", "localhost:1234")
	if err != nil {
		log.Fatal("net.Dial:", err)
	}

	client := rpc.NewClientWithCodec(jsonrpc.NewClientCodec(conn))

	var param pb.String = pb.String{
		Value: "龚凌锋",
	}
	var reply *pb.String = new(pb.String)
	err = client.Call("HelloService.Hello", param, &reply)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(reply)
	type MyString struct {
		Value string
	}
	var param2 MyString = MyString{Value: "结构体跟pb里的差不多也是可以的,对象名不会出现在json里，反射技术能再转成类似的结构体"}
	var reply2 *MyString = new(MyString)
	err = client.Call("HelloService.Hello", param2, &reply2)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(reply2)

}
